package org.puppet.game;

import java.util.LinkedList;
import java.util.List;

public class Broadcaster<T extends Controller> {

	List<T> controllers = new LinkedList<T>();

	public void reg(T controller) {
		controllers.add(controller);
	}

	public void unreg(T controller) {
		controllers.remove(controller);
	}

	public boolean broadcast(Integer eventId, Object e) {
		boolean result = true;
		for (int i = 0, len = controllers.size(); i < len; i++) {
			T c = controllers.get(i);
			result = c.action(eventId, e);
			if (!result)
				return false;
		}

		return result;
	}

	public List<T> getControllers() {
		return controllers;
	}
}
